package com.qen.service;

import cn.hutool.core.lang.Assert;
import com.qen.repository.BaseDao;
import com.qen.wrapper.Wrapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @author licz
 * @data 2025年05月22日 4:41 PM
 */
public abstract class CrudService<T, M extends BaseDao<T>>
        extends AbstractService<T, M> {

    @Autowired
    protected M baseDao;

    @Override
    public BaseDao getBaseDao() {
        Assert.notNull(this.baseDao, "baseDao不能为null");
        return this.baseDao;
    }

    @Override
    public void updateIfNotNull(Map<String, Object> obj) {
        getBaseDao().updateIfNotNull(obj);
    }

    @Override
    public void deleteEntityByKey(Serializable key) {
        getBaseDao().deleteEntityByKey(key);
    }

    @Override
    public void updateBatchIfNotNull(List<T> list) {
        getBaseDao().updateBatchIfNotNull(list);
    }

    @Override
    public <E> void addBatch(List<E> list) {
        getBaseDao().addBatch(list);
    }

    @Override
    public <E> void deleteEntityByKey(Serializable key, Class<E> clazz) {
        getBaseDao().deleteEntityByKey(key, clazz);
    }

    @Override
    public <E> Object saveEntity(E entity) {
        return getBaseDao().saveEntity(entity);
    }

    @Override
    public <E> void saveBatch(List<E> list) {
        getBaseDao().saveBatch(list);
    }

    @Override
    public <E> void upsertByKey(List<E> list, String[] uniqueKeyNames) {
        getBaseDao().upsertByKey(list, uniqueKeyNames);
    }

    @Override
    public <E> void upsertByKey(E obj, String[] uniqueKeyNames) {
        getBaseDao().upsertByKey(obj, uniqueKeyNames);
    }

    @Override
    public <E> void updateBatchIfNotNull(Class clazz, List<E> list) {
        getBaseDao().updateBatchIfNotNull(clazz, list);
    }

    @Override
    public <E> void deleteEntity(E entity) {
        getBaseDao().deleteEntity(entity);
    }

    @Override
    public <E> Object addEntity(E entity) {
        return getBaseDao().addEntity(entity);
    }

    @Override
    public <E> Object updateEntity(E entity) {
        return getBaseDao().updateEntity(entity);
    }

    @Override
    public <E> void updateBatch(List<E> list) {
        getBaseDao().updateBatch(list);
    }

    @Override
    public <E> void updateIfNotNull(E entity) {
        getBaseDao().updateIfNotNull(entity);
    }

    @Override
    public Integer sqlOperater(String sql, Map valuemap) {
        return getBaseDao().sqlOperater(sql, valuemap);
    }

    @Override
    public int delete(Wrapper<T> queryWrapper) {
        return getBaseDao().delete(queryWrapper);
    }

    @Override
    public <E> int update(E entity, Wrapper<E> wrapper) {
        return getBaseDao().update(entity, wrapper);
    }

}
